home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ColorPicker.h
-
- Contains: The public Color Picker Manager routines and data structures.
-
- Written by: Shannon Holland
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <66> 2/7/94 SAH Moved typedef inside #ifndef to stop compile errors for people
- who have included the old headers
- <65> 11/15/93 SAH Added a new __COLORPICKER__ define so that we don't re-include
- ourselves. Also added more checks for __PICKER__ in case people
- include us over the old header file.
- <64> 11/8/93 SAH Fixed header
- <63> 11/8/93 SAH Added gestalt selector.
-
- */
-
- #ifndef __COLORPICKER__
- #define __COLORPICKER__
-
- #include <QuickDraw.h>
- #include <Events.h>
- #include <Balloons.h>
-
- #ifndef ColorPicker
- #define ColorPicker
-
- #define kDefaultWidth 383
- #define kDefaultHeight 238
-
- // our gestalt selector
- #define gestaltColorPicker 'cpkr'
-
-
- /* Data structures and flags */
-
- #ifndef __CMAPPLICATION__
- #ifndef CMApplication
-
- /* define some colorsync types in case the caller didn't include them first */
-
- typedef struct CMPRofile **CMProfileHandle;
-
- typedef struct {
- unsigned short X; /* these should be 1.15 fixed numbers */
- unsigned short Y;
- unsigned short Z;
- } XYZColor;
-
- typedef struct {
- unsigned short c; /* these should be 1.15 fixed numbers */
- unsigned short m;
- unsigned short y;
- unsigned short k;
- } CMYKColor;
-
- typedef union {
- RGBColor rgb;
- XYZColor xyz;
- CMYKColor cmyk;
- unsigned short reserved[4];
- } CMColor, *CMColorList;
-
- #endif
- #endif
-
- typedef struct PMColor
- {
- CMProfileHandle profile;
- CMColor color;
- } PMColor,*PMColorPtr;
-
- typedef struct PrivatePickerRecord **picker;
-
- /*
- * The actions returned to the application from DoPickerEvent
- */
- enum PickerAction
- {
- kDidNothing,
- kColorChanged,
- kOkHit,
- kCancelHit,
- kNewPickerChosen,
- kApplItemHit
- };
-
- typedef short PickerAction;
-
- /*
- * The types of colors a picker must maintain
- */
- enum ColorTypes
- {
- kOriginalColor, // the original color passed to the picker manager
- kNewColor // the current color the user has chosen
- };
-
- typedef short ColorType;
-
- /*
- * The types of edit operations that are sent with the kEdit message
- */
- enum EditOperations
- {
- kCut,
- kCopy,
- kPaste,
- kClear,
- kUndo
- };
-
- typedef short EditOperation;
-
- /*
- * The Item hit modifiers. These are sent along with the itemHit message and inform the picker
- * of what it was that caused the item hit.
- */
- enum ItemHitModiefiers
- {
- kMouseDown, // mouseDown on item
- kKeyDown, // keydown in current edit item
- kFieldEntered, // tab into an edit field
- kFieldLeft, // tab out of an edit field
- kCutOp, // cut in current edit field
- kCopyOp, // copy in current edit field
- kPasteOp, // paste in current edit field
- kClearOp, // clear in current edit field
- kUndoOp // undo in current edit field
- };
-
- typedef short ItemModifier;
-
-
- /*
- * The dialog placement specifiers. These tell the picker manager where to place
- * the picker dialog (used for system dialogs).
- */
-
- enum DialogPlacementSpecifiers
- {
- kAtSpecifiedOrigin,
- kDeepestColorScreen,
- kCenterOnMainScreen
- };
-
- typedef short DialogPlacementSpec;
-
-
- /*
- * Picker flags
- */
-
- // these flags may be set by the app and are passed through to the picker
- #define DialogIsMoveable 1 // the dialog can be moved
- #define DialogIsModal 2 // the dialog is modal
- #define CanModifyPalette 4 // the picker is allowed to install a palette
- #define CanAnimatePalette 8 // the picker is allowed to animate the palette
- #define AppIsColorSyncAware 16 // The application is ColorSync aware and can therfore
- // convert colors between spaces (ie it can accept non-RGB
- // colors)
-
- // these flags are set by the picker manager (overriding any application settings)
- #define InSystemDialog 32 // the picker is in a system dialog
- #define InApplicationDialog 64 // the picker is in an application dialog
- #define InPickerDialog 128 // the picker is in its own dialog
- #define DetachedFromChoices 256 // the picker has been detached from the choices
- // list
-
-
- /*
- * Picker attributes (bits 23 to 0 in the componentFlags field of the component thng)
- */
-
- #define CanDoColor 1 // the picker can live in Color QD Environments
- #define CanDoBlackWhite 2 // the picker can live in Classic QD Environments
- #define AlwaysModifiesPalette 4 // the picker will modify palette entries on indexed
- // devices
- #define MayModifyPalette 8 // the picker will modify palette if told it can
- #define PickerIsColorSyncAware 16 // the picker is ColorSync aware and can accept
- // non-RGB colors
- #define CanDoSystemDialog 32 // the picker can live inside a system dialog
- #define CanDoApplDialog 64 // the picker can live inside an application
- #define HasOwnDialog 128 // the picker has its own dialog
- #define CanDetach 256 // the picker can detach from a system dialog
-
-
- /*
- * The extended picker data structure list-view information the component manager doesn't keep.
- * around. This data is accessed via the kGetIconData message.
- */
-
- typedef struct PickerIconData
- {
- short scriptCode;
- short iconSuiteID;
- ResType helpResType;
- short helpResID;
- } PickerIconData;
-
- typedef struct PickerInitData
- {
- DialogPtr pickerDialog;
- DialogPtr choicesDialog;
- long flags;
- picker yourself;
- } PickerInitData;
-
- /*
- * Picker error messages
- */
-
- enum
- {
- firstPickerError = -4000,
-
- invalidPickerType = firstPickerError,
- requiredFlagsDontMatch = -4001,
- pickerResourceError = -4002,
- cantLoadPicker = -4003,
- cantCreatePickerWindow = -4004,
- cantLoadPackage = -4005,
- pickerCantLive = -4006,
- colorSyncNotInstalled = -4007,
- badProfileError = -4008,
- noHelpForItem = -4009
- };
-
- /*
- * The application filter proc for DoPickerEvent
- */
-
- typedef pascal Boolean (*UserEventProc)(EventRecord *event);
-
- /*
- * The application proc to be called when the color changes (called by the picker itself).
- */
-
- typedef pascal void (*ColorChangedProc)(long userData,PMColorPtr newColor);
-
- enum EventForcasters
- {
- kNoForcast, // no forcast (eg an update event)
- kMenuChoice, // this event will cause a menu to be chosen
- kDialogAccept, // the dialog will be accepted
- kDialogCancel, // the dialog will be cancelled
- kLeaveFocus, // the focus will leave the picker
- kPickerSwitch, // new picker chosen in more choices list
- kNormalKeyDown, // a normal key down to an edit field
- kNormalMouseDown // a normal click within the picker's focus
- };
-
- typedef short EventForcaster;
-
- // the structure that details the location of the edit menu and its items
- typedef struct MenuItemInfo
- {
- short editMenuID;
- short cutItem;
- short copyItem;
- short pasteItem;
- short clearItem;
- short undoItem;
- } MenuItemInfo;
-
- // a structure which details the state the picker wishes the edit menu items to be in
- typedef struct MenuState
- {
- Boolean cutEnabled;
- Boolean copyEnabled;
- Boolean pasteEnabled;
- Boolean clearEnabled;
- Boolean undoEnabled;
- Str255 undoString;
- } MenuState;
-
- typedef struct ColorPickerInfo
- {
- PMColor theColor;
- CMProfileHandle dstProfile;
- long flags;
- DialogPlacementSpec placeWhere;
- Point dialogOrigin;
- long pickerType;
- UserEventProc eventProc;
- ColorChangedProc colorProc;
- long colorProcData;
- Str255 prompt;
- MenuItemInfo mInfo;
- Boolean newColorChosen;
- } ColorPickerInfo;
-
- typedef struct SystemDialogInfo
- {
- long flags;
- long pickerType;
- DialogPlacementSpec placeWhere;
- Point dialogOrigin;
- MenuItemInfo mInfo;
- } SystemDialogInfo;
-
- typedef struct PickerDialogInfo
- {
- long flags;
- long pickerType;
- Point *dialogOrigin;
- MenuItemInfo mInfo;
- } PickerDialogInfo;
-
- typedef struct ApplicationDialogInfo
- {
- long flags;
- long pickerType;
- DialogPtr theDialog;
- Point pickerOrigin;
- MenuItemInfo mInfo;
- } ApplicationDialogInfo;
-
- typedef struct EventData
- {
- EventRecord *event;
- PickerAction action;
- short itemHit;
- Boolean handled;
- ColorChangedProc colorProc;
- long colorProcData;
- EventForcaster forcast;
- } EventData;
-
- typedef struct EditData
- {
- EditOperation theEdit;
- PickerAction action;
- Boolean handled;
- } EditData;
-
- typedef struct ItemHitData
- {
- short itemHit;
- ItemModifier iMod;
- PickerAction action;
- ColorChangedProc colorProc;
- long colorProcData;
- Point where;
- } ItemHitData;
-
-
- typedef struct HelpItemInfo
- {
- long options;
- Point tip;
- Rect altRect;
- short theProc;
- short variant;
- HMMessageRecord helpMessage;
- } HelpItemInfo;
-
- /* High-level routines */
- #ifndef __PICKER__
- pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor);
- #endif
- pascal OSErr PickColor(ColorPickerInfo *theColorInfo);
-
- /* Low-level routines */
- pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker);
- pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker);
- pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker);
- pascal OSErr DisposeColorPicker(picker thePicker);
- pascal OSErr SetPickerVisibility(picker thePicker,short visible);
- pascal OSErr GetPickerVisibility(picker thePicker,Boolean *vis);
- pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString);
- pascal OSErr DoPickerEvent(picker thePicker,EventData *data);
- pascal OSErr DoPickerEdit(picker thePicker,EditData *data);
- pascal OSErr DoPickerDraw(picker thePicker);
- pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
- pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
- pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile);
- pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile);
- pascal OSErr GetPickerOrigin(picker thePicker,Point *where);
- pascal OSErr SetPickerOrigin(picker thePicker,Point where);
- pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState);
- pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo);
-
-
- #ifndef __PICKER__
-
- /* stuff from the old Picker.h */
-
- enum {MaxSmallFract = 0x0000FFFF}; /*Maximum small fract value, as long*/
-
-
- /* A SmallFract value is just the fractional part of a Fixed number,
- which is the low order word. SmallFracts are used to save room,
- and to be compatible with Quickdraw's RGBColor. They can be
- assigned directly to and from INTEGERs. */
-
- typedef unsigned short SmallFract; /* Unsigned fraction between 0 and 1 */
-
- /* For developmental simplicity in switching between the HLS and HSV
- models, HLS is reordered into HSL. Thus both models start with
- hue and saturation values; value/lightness/brightness is last. */
-
-
-
- struct HSVColor {
- SmallFract hue; /*Fraction of circle, red at 0*/
- SmallFract saturation; /*0-1, 0 for gray, 1 for pure color*/
- SmallFract value; /*0-1, 0 for black, 1 for max intensity*/
- };
-
- typedef struct HSVColor HSVColor;
- /* For developmental simplicity in switching between the HLS and HSVmodels, HLS
- is reordered into HSL. Thus both models start with hue and saturation values;
- value/lightness/brightness is last. */
- struct HSLColor {
- SmallFract hue; /*Fraction of circle, red at 0*/
- SmallFract saturation; /*0-1, 0 for gray, 1 for pure color*/
- SmallFract lightness; /*0-1, 0 for black, 1 for white*/
- };
-
- typedef struct HSLColor HSLColor;
-
- struct CMYColor {
- SmallFract cyan;
- SmallFract magenta;
- SmallFract yellow;
- };
-
- typedef struct CMYColor CMYColor;
-
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #ifndef __PICKER__
- pascal SmallFract Fix2SmallFract(Fixed f)
- = {0x3F3C,0x0001,0xA82E};
- pascal Fixed SmallFract2Fix(SmallFract s)
- = {0x3F3C,0x0002,0xA82E};
- pascal void CMY2RGB(const CMYColor *cColor,RGBColor *rColor)
- = {0x3F3C,0x0003,0xA82E};
- pascal void RGB2CMY(const RGBColor *rColor,CMYColor *cColor)
- = {0x3F3C,0x0004,0xA82E};
- pascal void HSL2RGB(const HSLColor *hColor,RGBColor *rColor)
- = {0x3F3C,0x0005,0xA82E};
- pascal void RGB2HSL(const RGBColor *rColor,HSLColor *hColor)
- = {0x3F3C,0x0006,0xA82E};
- pascal void HSV2RGB(const HSVColor *hColor,RGBColor *rColor)
- = {0x3F3C,0x0007,0xA82E};
- pascal void RGB2HSV(const RGBColor *rColor,HSVColor *hColor)
- = {0x3F3C,0x0008,0xA82E};
- #endif
-
- #ifndef RUN_LINKED_IN
- #ifndef __PICKER__
- pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor)
- = {0x3F3C,0x0009,0xA82E};
- #endif
- pascal OSErr PickColor(ColorPickerInfo *theColorInfo)
- = {0x3F3C,0x0213,0xA82E};
- pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker)
- = {0x3F3C,0x0414,0xA82E};
- pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker)
- = {0x3F3C,0x0415,0xA82E};
- pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker)
- = {0x3F3C,0x0416,0xA82E};
- pascal OSErr DisposeColorPicker(picker thePicker)
- = {0x3F3C,0x0217,0xA82E};
- pascal OSErr GetPickerVisibility(picker thePicker,Boolean *visible)
- = {0x3F3C,0x0418,0xA82E};
- pascal OSErr SetPickerVisibility(picker thePicker,short visible)
- = {0x3F3C,0x0319,0xA82E};
- pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString)
- = {0x3F3C,0x041a,0xA82E};
- pascal OSErr DoPickerEvent(picker thePicker,EventData *data)
- = {0x3F3C,0x041b,0xA82E};
- pascal OSErr DoPickerEdit(picker thePicker,EditData *data)
- = {0x3F3C,0x041c,0xA82E};
- pascal OSErr DoPickerDraw(picker thePicker)
- = {0x3F3C,0x021d,0xA82E};
- pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
- = {0x3F3C,0x051e,0xA82E};
- pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
- = {0x3F3C,0x051f,0xA82E};
- pascal OSErr GetPickerOrigin(picker thePicker,Point *where)
- = {0x3F3C,0x0420,0xA82E};
- pascal OSErr SetPickerOrigin(picker thePicker,Point where)
- = {0x3F3C,0x0421,0xA82E};
- pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile)
- = {0x3F3C,0x0422,0xA82E};
- pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile)
- = {0x3F3C,0x0423,0xA82E};
- pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState)
- = {0x3F3C,0x0424,0xA82E};
- pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo)
- = {0x3F3C,0x0625,0xA82E};
-
- #endif
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-
- #endif